<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <button id="btn">click</button>

    <script>

        function debounce(fn,delay=300){
            let timer = 0;
            return function(){
                timer && clearTimeout(timer);
                timer = setTimeout(()=>{
                    fn.apply(this,arguments);
                    timer = 0;
                },delay)
            }
        }
        function throttle(fn,delay=300){
            let timer = 0;
            return function(){
                if(timer){
                    return;
                }
                timer = setTimeout(()=>{
                    fn.apply(this,arguments);
                    timer = 0;
                },delay)
            }
        }

        let btn = document.querySelector("#btn");
        function test(e){
            // console.log('e:',e)
            console.log(new Date())
        }
        btn.addEventListener('click',throttle(test))


    </script>
    <script>
        const obj1 = {a: {b: {c: 123 } },d:new Date(),r:/\d+/,e:[11,22],f:function(){} }
        
        function deepCopy(data){
            if(typeof data !== 'object'){
                return data
            }
            if(data === null){
                return data
            }
            if(data.constructor === Date){
                return new Date(data)
            }
            if(data.constructor === RegExp){
                return new RegExp(data)
            }
            let newData = new data.constructor();
            let keys = Object.keys(data);
            for(let i=0;i<keys.length;i++){
                let val = data[keys[i]];
                newData[keys[i]] = typeof val === 'object' ? deepCopy(val):val;
            }
            return newData
        }
        // console.log(deepCopy(obj1))
    </script>
    
    <script>
        const originArray = [{name: '小明', a: 1}, {name: '小明', b: 1}, {name: '小红', a: 1}]
        function handleFn(arr){
            let obj = {}
            arr.forEach(item=>{

                if(obj[item.name]){
                    obj[item.name].push(item)
                }else{
                    obj[item.name] = [item]
                }
            })
            return obj;
        }
        // console.log(handleFn(originArray))

        const obj = {a: {b: {c: 123 } } }

        function objGet(obj,key){
            let keys = key.split('.')
            let n = keys.length;
            let i=1;
            let val = obj[keys[0]]
            while(i<n){
                val = val[keys[i]]
                i++;
            }
            return val;
        }

        // console.log(objGet(obj,'a.b'))
        // console.log(objGet(obj,'a.b.c'))


    </script>
</body>
</html>